<%@page import="com.stms.bean.Student"%>
<%@page import="com.stms.dao.StudentDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>学生信息管理系统-修改学生</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>

<div class="header">
    <div class="content of">
        <h1 class="logo fl">学生信息管理系统</h1>
        <c:choose>
            <c:when test="${isLogin != null && isLogin}">
                <div class="user fr">
                    <span class="red">${loginUser.getUserName()}</span>&nbsp;&nbsp;欢迎回来&nbsp;&nbsp;
                    <a href="doLogout"><button>退出登录</button></a>
                </div>
            </c:when>
            <c:otherwise>
                <form class="user fr" action="doLogin" method="post" onsubmit="return loginVerify();">
                    <input type="text" id="uName" name="uName">
                    <input type="password" id="pWord" name="pWord">
                    <button type="submit">登录</button>
                    <a href="register.jsp"><button>注册</button></a>
                </form>
                <p class="red">${msg}</p>
            </c:otherwise>
        </c:choose>
    </div>
</div>
<div class="content of">
    <div class="side fl">
        <ul>
            <li><a href="index.jsp">首页</a></li>
            <li><a href="studentList.jsp">学生管理</a></li>
            <li><a href="addStudent.jsp">添加学生</a></li>
        </ul>
    </div>

    <%
        // 获取传入的学生ID
        String Id_str = request.getParameter("id");
        Student student = null;
        if (Id_str != null && !Id_str.isEmpty()) {
            int studentId = Integer.parseInt(Id_str);
            StudentDao studentDao = new StudentDao();
            student = studentDao.selectStudentById(studentId);
            request.setAttribute("student", student);
        }
    %>

    <div class="main fr">
        <h2 class="ct">修改学生</h2>
        <!-- 表单 -->
        <form action="updateStudent" method="post" onsubmit="return editStudentVerify();">
            <input type="hidden" name="id" value="${student.id}">
            <label>姓名：</label>
            <input type="text" id="stuName" name="stuName" value="${student.stuName}"><br>
            <label>班级：</label>
            <input type="text" id="className" name="className" value="${student.className}"><br>
            <label>学号：</label>
            <input type="text" id="stuNo" name="stuNo" value="${student.stuNo}" readonly><br>
            <label>性别：</label>
            男<input type="radio" name="sex" value="男" ${student.sex == '男' ? 'checked' : ''}>
            女<input type="radio" name="sex" value="女" ${student.sex == '女' ? 'checked' : ''}><br>
            <label>年龄：</label>
            <input type="number" name="age" value="${student.age}"><br>
            <label>籍贯：</label>
            <input type="text" name="addr" value="${student.addr}"><br>
            <button type="submit">保存修改</button>
<%--            <button type="reset">重置</button>--%>
        </form>
    </div>
</div>
<div class="footer">
    <div class="content">
        <p class="ct">版权所有&copy;湖南大众传媒职业技术大学</p>
    </div>
</div>
<script type="text/javascript" src="js/all.js"></script>
</body>
</html>